package com.ccoffers.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.ccoffers.model.shopping.ShoppingCategory;
import com.ccoffers.service.impl.CRUDServiceImpl;

@Controller
@RequestMapping(value="/shoppingCategory")
public class ShoppingCategoryAdminController {
	@Autowired
	private CRUDServiceImpl<ShoppingCategory> shoppingCategoryService;
	
	@RequestMapping(value="/add")
	public String addShoppingCategory(@RequestParam("shoppingCategory") String shoppingCategory, Model model){
		ShoppingCategory category = new ShoppingCategory();
		category.setShoppingCategory(shoppingCategory);
		shoppingCategoryService.update(category);
		return "redirect:/internal/admin";
	}
	
	@RequestMapping(value="/delete")
	public String deleteCreditCardCompany(@RequestParam("id") Long id, Model model){
		shoppingCategoryService.delete(shoppingCategoryService.retrieve(ShoppingCategory.class, id));
		return "redirect:/internal/admin";
	}
}
